﻿
@{
    <script src="~/js/jquery-1.11.1.js"></script>
    <link href="~/css/table.css" rel="stylesheet" />
    <link href="~/css/cwcalendar.css" rel="stylesheet" />
    <script src="~/js/vue.js"></script>
}
@using Model
@model List<salary_standard_details>
<body>
    <div id="app">
        <form method="post" id="form1">
            <input type="hidden" name="standard.ssdId" value="1259">

            <table width="100%">
                <tr>
                    <td>
                        <font color="#0000CC">您正在做的业务是:人力资源管理--薪酬标准管理--薪酬标准登记变更</font>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div align="right">
                            <input type="button" value="重新提交" class="BUTTON_STYLE1" v-on:click="Upd()">
                            <input type="button" value="返回" onclick="history.back();" class="BUTTON_STYLE1">
                        </div>
                    </td>
                </tr>
            </table>

            <table width="100%" border="1" cellpadding=0 cellspacing=1
                   bordercolorlight='#848284' bordercolordark='#eeeeee'
                   class="TABLE_STYLE1">
                <tr>
                    <td width="12%" class="TD_STYLE1">
                        薪酬编号
                    </td>
                    <td width="15%" class="TD_STYLE2">
                        <input type="text" name="standard_id" id="standard_id" readonly />
                    </td>
                    <td width="12%" class="TD_STYLE1">
                        薪酬标准名称
                    </td>
                    <td width="11%" class="TD_STYLE2">
                        <input type="text" name="standard_name" id="standard_name" class="INPUT_STYLE2">
                        <span id="bzmc" style="color:red;font-weight:bold;"></span>
                    </td>
                    <td width="11%" class="TD_STYLE1">
                        薪酬总额
                    </td>
                    <td width="17%" class="TD_STYLE2">
                        <input type="text" name="salary_sum" readonly id="sumSalary" class="INPUT_STYLE2">
                    </td>
                    <td width="12%" class="TD_STYLE1">
                        &nbsp;
                    </td>
                    <td width="10%" class="TD_STYLE2">
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td class="TD_STYLE1">
                        制定人
                    </td>
                    <td class="TD_STYLE2">
                        <input type="text" name="designer" id="designer" class="INPUT_STYLE2">
                        <span id="zdr" style="color:red;font-weight:bold;"></span>
                    </td>
                    <td class="TD_STYLE1">
                        变更人
                    </td>
                    <td class="TD_STYLE2">
                        <input type="text" name="changer" id="changer" value="better_admin" class="INPUT_STYLE2">
                        <span id="bgr" style="color:red;font-weight:bold;"></span>
                    </td>
                    <td class="TD_STYLE1">
                        变更时间
                    </td>
                    <td class="TD_STYLE2">
                        <input type="text" name="change_time" readonly id="Tdate" class="INPUT_STYLE2">
                    </td>
                    <td class="TD_STYLE1">
                        &nbsp;
                    </td>
                    <td class="TD_STYLE2">
                        &nbsp;
                    </td>
                </tr>

                <tr>
                    <td class="TD_STYLE1">
                        备注
                    </td>
                    <td colspan="7" class="TD_STYLE2">
                        <textarea name="remark" id="remark" rows="4" class="INPUT_STYLE2"></textarea>
                        <span id="bz" style="color:red;font-weight:bold;"></span>
                    </td>
                </tr>
                <tr>
                    <td class="TD_STYLE1">
                        序号
                    </td>
                    <td colspan="3" class="TD_STYLE1">
                        薪酬项目名称
                    </td>
                    <td colspan="4" class="TD_STYLE1">
                        金额
                    </td>
                </tr>
                <tbody id="tbody">
                    <tr class="TD_STYLE2" v-for="(item,index) in ds">
                        <td align="center">
                            {{item.item_id}}
                            <input type="hidden" name="item_id" id="item_id" :value="item.item_id">
                        </td>
                        <td colspan="3">
                            {{item.item_name}}
                            <input type="hidden" id="item_name" name="iname" :value="item.item_name">
                        </td>
                        <td>
                            <input type="text" id="salary" name="salary" :value="item.salary"
                                   onkeyup="countMoney('6','salary')" class="INPUT_STYLE2">
                        </td>
                        <td colspan="3">
                            &nbsp;
                        </td>
                    </tr>
                </tbody>
            </table>
        </form>
    </div>
    <script type="text/javascript">
        function countMoney(obj, o) {
            obj = vm.leg;
            if (isNaN(document.getElementById(o).value) || document.getElementById(o).value < 0) {
                alert("金额填写错误!");
                document.getElementById(o).value = "0.00";
                return;
            }
            var sum = 0;
            for (var i = 0; i < obj; i++) {
                var salary = $("#tbody tr:nth-child(" + (i + 1) + ") td:nth-child(3) input").val();
                if (salary == null || salary == "" || salary == NaN || salary == "0.00") {
                    salary = 0;
                }
                sum = Number(sum) + Number(salary);
            }
            document.getElementById("sumSalary").value = sum;

        }
        function time() {
            var tdate = document.getElementById("Tdate");
            var d = new Date();
            var y = d.getFullYear();
            var moth = d.getMonth() + 1;
            var date = d.getDate();
            var h = d.getHours();
            var m = d.getMinutes();
            var s = d.getSeconds();
            var hh = 20 - 1 - h;
            var mm = 60 - 1 - m;
            var ss = 60 - s;
            if (hh > 0) {
                mm = mm + 60 * hh;
            }
            if (moth < 10) {
                moth = "0" + moth;
            }
            if (date < 10) {
                date = "0" + date;
            }
            if (h < 10) {
                h = "0" + h;
            }
            if (m < 10) {
                m = "0" + m;
            }
            if (s < 10) {
                s = "0" + s;
            }
            if (mm < 10) {
                mm = "0" + mm;
            }
            if (ss < 10) {
                ss = "0" + ss;
            }

            tdate.value = y + "-" + moth + "-" + date + " " + h + ":" + m + ":" + s;

        }
        window.onload = time;
        var out = window.setInterval(time, 1000);

        var vm = new Vue({
            el: "#app",
            data: {
                dt: [],
                ds: [],
                staid: 0,
                leg: 0,
                stdid: 0,
                dlsj: 0,
                djr: "",
                bz: "",
            },
            methods: {
                load: function () {
                    var t = this;
                    $.ajax({
                        url: "/xinchoubiaozhun/salarystandard_check1",
                        type: "get",
                        success: function (msg) {
                            var dr = eval(msg);
                            t.dt = dr["dt"];
                            t.ds = dr["ds"];
                            t.leg = dr["leg"];
                            t.staid = dr["dt"].ssd_id;
                            t.stdid = dr["ds"][0]["sdt_id"];
                            t.dlsj = dr["dt"].regist_time;
                            t.djr = dr["dt"].register;
                            t.bz = dr["dt"].remark;
                            $("#standard_id").val(t.dt.standard_id);
                            $("#standard_name").val(t.dt.standard_name);
                            $("#sumSalary").val(t.dt.salary_sum);
                            $("#designer").val(t.dt.designer);
                        }
                    })
                },
                xmUpd: function () {
                    var t = this;
                    for (var i = 0; i < vm.leg; i++) {
                        var xh = $("#tbody tr:nth-child(" + (i + 1) + ") td:nth-child(1) input").val();
                        var name = $("#tbody tr:nth-child(" + (i + 1) + ") td:nth-child(2) input").val();
                        var salary = $("#tbody tr:nth-child(" + (i + 1) + ") td:nth-child(3) input").val();
                        $.ajax({
                            url: "/xinchoubiaozhun/UpdateXcxm",
                            type: "post",
                            data: { "item_name": name, "standard_id": $("#standard_id").val(), "item_id": xh, "standard_name": $("#standard_name").val(), "salary": salary, "sdt_id": t.stdid },
                            success: function (msg) {
                                if (msg > 0) {
                                    location.href = '/xinchoubiaozhun/salarystandard_change_success';
                                } else {
                                    alert('更改失败！');
                                    location.href = '/xinchoubiaozhun/salarystandard_change_list';
                                }
                            }
                        })
                    }

                },
                Upd: function () {
                    var t = this;
                    if ($("#standard_name").val() == "") {
                        document.getElementById("bzmc").innerHTML = "请输入薪酬标准名称！";
                        return false;
                    } else if ($("#designer").val() == "") {
                        document.getElementById("zdr").innerHTML = "请输入制定人名称！";
                        return false;
                    }
                    else if ($("#checker").val() == "") {
                        document.getElementById("fhr").innerHTML = "请输入复核人名称！";
                        return false
                    }
                    else if ($("#remark").val() == "") {
                        document.getElementById("bz").innerHTML = "请输入备注！";
                        return false;
                    } else {
                        $.ajax({
                            url: "/xinchoubiaozhun/salarystandard_change?ssd_id=" + t.staid + "&regist_time=" + t.dlsj + "&register=" + t.djr + "&remark=" + t.bz,
                            type: "post",
                            data: $("#form1").serialize(),
                            success: function (msg) {
                                if (msg > 0) {
                                    t.xmUpd();
                                } else {
                                    alert('更改失败！');
                                    location.href = '/xinchoubiaozhun/salarystandard_change_list';
                                }
                            }
                        })
                    }
                }
            },
            mounted: function () {
                this.load();
            }
        });
    </script>
</body>
